home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Question on pointers
- Date: Tue, 09 Apr 96 12:02:31 GMT
- Organization: none
- Message-ID: <829051351snz@genesis.demon.co.uk>
- References: <1996Apr8.233330.139449@forest>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <1996Apr8.233330.139449@forest> ebromber@forest.drew.edu writes:
-
- >In a program there is an array of structs. One of the headers for a
- >function says void pop(stack *). My question is shouldn't there be a name
- >or identifier after the asterisk?
-
- If it is just a declaration of the function then, no, you don't need to
- name the parameters. All a declaration such as this does is provide type
- information so that in a function call the compiler can validate the
- arguments, perform any necessary conversions and generate the correct call
- code. For a function definition i.e. where you define a function body you
- must name the parameters.
-
- void pop(stack *); /* Simple (prototyped) declaration */
-
- /* The function definition */
-
- void pop(stack *sp)
- {
- /* Code using sp */
- }
-
- >My friend says that it is the address of
- >a stack in the array. If this is true, how could I access the thing
- >pointed to?
-
- In the example above you can refer to the thing pointed to using *sp in
- the function.
-
- >Here are some lines which define a stack
- >
- >typedef struct item item;
- >struct item {
- > struct item *next;
- > char c;
- > }
- >typedef item *stack;
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-